import Big from 'big.js'
export const  lpMap = {
    "0x87a0183e4460D313257627B4cBB4E59cfcB7F7bb"  :["0x2E51b6f3181b342d098B1a939Ae1944ED6768fd4","0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"], 
    "0x0eD7e52944161450477ee417DE9Cd3a859b14fD0"  :["0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82","0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"], 
    "0x58F876857a02D6762E0101bb5C46A8c1ED44Dc16"  :["0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56","0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"], 
    "0x16b9a82891338f9bA80E2D6970FddA79D1eb0daE"  :["0x55d398326f99059ff775485246999027b3197955","0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"], 
} 
let amount=0;
async function getBanlanceOf(instance,address){ return instance.methods.balanceOf(address).call({from:window.addr, }) } 
   
 
 
export const  calc = async (data,web3)=>{ 
    amount = window.Web3.utils.toBN("1000000000000000000")
    console.log(data)
    calcLP(data,web3)
    calcSingle(data,web3)

}

export const  calcSingle = async (data,web3)=>{ 
    console.log(data)
    async function getEach(addr){ 
        var arr = [
        await web3.TotalDeposit(addr).call(window.sender),
        await web3.userTotal(addr).call(window.sender),
        await web3.myTotalDeposit(window.addr,addr).call(window.sender),
        await web3.MytotalReward(window.addr).call(window.sender),
        await web3.getAmountsOut(amount,[ addr ,"0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"]).call(window.sender),
        await web3.getAmountsOut(amount,["0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c","0x55d398326f99059ff775485246999027b3197955"]).call(window.sender)
        ] 
        console.log("单币部分的计算",arr) 
    }
    data.singleList.map(e=>{
        getEach(e)
    })
    var s =   await web3.TotalDeposit("0x2E51b6f3181b342d098B1a939Ae1944ED6768fd4").call(window.sender)
    console.log("s",s)

}

export const  calcLP = async (data,web3)=>{ 
    console.log(data,"计算一下这里的汇率常量")
   
    
    // web3.getAmountsOut(amount,[map.bnb,map.usdt]).call(window.sender)

    async function getEach(addr){ 
     
        var arr = [
        await web3.TotalDepositLP(addr).call(window.sender),
        await web3.userTotalLP(addr).call(window.sender),
        await web3.myTotalDepositLP(window.addr,addr).call(window.sender),
        await web3.MytotalRewardLP(window.addr).call(window.sender),
        await web3.getAmountsOut(amount,[addr,"0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"]).call(window.sender),
        await web3.getAmountsOut(amount,["0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c","0x55d398326f99059ff775485246999027b3197955"]).call(window.sender)
        ] 
        console.log("res",arr)
        return ;
    }
    for(var i =0; i< data.lpList.length;i++){
        await getEach( data.lpList[i])
    } 
   var s =   await web3.TotalDepositLP("0x87a0183e4460D313257627B4cBB4E59cfcB7F7bb").call(window.sender)
   console.log("s",s)
   s =   await web3.userTotalLP("0x87a0183e4460D313257627B4cBB4E59cfcB7F7bb").call(window.sender)
   console.log("s",s)
   s = await web3.poolListLP ("0x87a0183e4460D313257627B4cBB4E59cfcB7F7bb").call(window.sender)
   console.log("s",s)
    
}

/*
data.lpList.map(async (e,i)=>{
    console.log(lpMap[e][0],lpMap[e][1])
    if(i < -1 ){
        var arr = [web3.getAmountsOut(amount,[lpMap[e][0],bnb]).call(window.sender),web3.getAmountsOut(amount,[bnb,usdt]).call(window.sender) ]
        const res = await Promise.all(arr)
        console.log("res",res)
    }  
})
*/